/** ===================================================================================
 * Copyright (C) 2021 FUXINKUNPENG.  All rights reserved.
 *
 * This file is copyrighted and contains proprietary information of FUXINKUNPENG.
 * It is forbidden to distribute any parts of FUXINKUNPENG OFD SDK to any third parties
 * or general public without permission from FUXINKUNPENG.
 *
 *
 *  ==================================================================================
 */
#import <Foundation/Foundation.h>

//A utility class specific for string size calculate function for drawing string
//the font, size is fixed when initialize
//aligment is left
//line break mode is word break
//on May 17, 2012, add new methods for getting last index of wrapper text coreText!

//the margin for UITextView input. the real text width should be UITextView's width-2*UITextView_Margin
#define UITextView_Margin 8.0

@interface RDKStringDrawUtil : NSObject

@property (nonatomic, readonly, assign) float singleLineHeight; //cache for single line height

//cache for getReturnRefinedString, in most case if no new line happen, no need to reculcuate
@property (nonatomic, retain) NSString *previousStr;
@property (nonatomic, retain) NSString *previousRetStr;
@property (nonatomic, assign) float previousHeight;

// the font and size used for the whole drawing
- (id)initWithFont:(UIFont *)font;

/**
 -------these three methods are not very accurate. it's used to guess one word in most cases (English, Chinese)----------
 is this string seperatable? not seperate for example, English word, symbol
 if English word, return 1
 if symbol, return 2
 if number, return 3
 other return 0
 */
+ (int)isSeparatable:(NSString *)str;
/// from the end, reduce one word
+ (NSString *)reductOneWord:(NSString *)str;
/// from the begin, get one word
+ (NSString *)startOneWord:(NSString *)str;

/// get height within a fixed width
+ (float)heightOfContent:(NSString *)content withinWidth:(float)width textfont:(UIFont *)textfont;
/// get width within a fixed height
+ (float)widthOfContent:(NSString *)content withinHeight:(float)height textfont:(UIFont *)textfont;

/// 计算文本的size
/// - Parameters:
///   - maxsize: maxSize
///   - content: content
///   - textfont: textfont
///   - breakMode: breakMode
///   - options: options
+ (CGSize)boundingRectWithMaxSize:(CGSize)maxsize
                          content:(NSString *)content
                         textfont:(UIFont *)textfont
                    lineBreakMode:(NSLineBreakMode)breakMode
                          options:(NSStringDrawingOptions)options;

/// get the end string index inside rectangle. if not enough to contain the string, it's the last index; else it's the last index shown in rect.
- (int)stringIndex:(NSString *)content insideSize:(CGSize)size needSufix:(BOOL)isSufix;

/// check the string (one character) is a sentence break symbol.  for example: .?!;。？！；
+ (BOOL)isSentenceBreakSymbol:(NSString *)str;

/// separate string by the separator.
/// it's not same as [NSString componentSeparate] as it will not have empty, and it contains the separator itself.
+ (NSArray *)seperateString:(NSString *)content bySeparator:(NSString *)separator;

/// remove the blank character between keyword which will make it cannot be found.
/// For example, in 乔布斯传, if search 乔布斯, the tempStr found is "Steve Jobs by Walter Isaacson | 史 蒂 夫 • 乔 布 斯 传"
/// For unknown reason, the keyword is added " " inside it so cause keyword cannot be found. Here need to remove the " " if can make keyword found.
+ (NSString *)removeBlankBetweenKeyword:(NSString *)content keyword:(NSString *)keyword;

/// 依赖于getReturnRefinedString,适用包含\n的字符串
- (NSString *)getHadReturnRefinedString:(NSString *)str forUITextViewWidth:(float)width;

/// used for free text annotation. the string is typed in UITextView and need to get a same wrapped string with "\n" inserted at exactly place.
/// use core text to calculate
- (NSString *)getReturnRefinedString:(NSString *)str forUITextViewWidth:(float)width;

/// Get language of string
+ (NSString*)languageForString:(NSString*)str;

/// get word range of string, including space, the best part is it supports all language including Chinese
+ (NSArray*)getUnitWordBoundary:(NSString*)str;

@end
